package pkg

import "github.com/gin-gonic/gin"

type Response struct {
	ctx *gin.Context
	State int
	Message string
	Payload interface{}
}


func ResponseError(state int, err error) Response {
	return Response{State:state, Message:err.Error()}
}

func ResponseSuccess(payload interface{}) Response {
	return Response{State:200, Payload:payload}
}

func (resp Response) Reply(ctx *gin.Context) {
	if resp.State == 200 {
		ctx.JSON(resp.State, gin.H{"payload":resp.Payload})
	} else {
		ctx.JSON(resp.State, gin.H{"error":resp.Message})
	}
}
